package com.onpositive.mediawiki.propertyparser;

import java.util.ArrayList;
import java.util.Map;

import com.onpositive.semantic.model.api.meta.IMeta;
import com.onpositive.semantic.model.api.property.IPropertyProvider;
import com.onpositive.units.AbstractPreprocessor;
import com.onpositive.units.AbstractValueParser;
import com.onpositive.units.ParsedLinkArray;
import com.onpositive.units.ParsedValue;

public class LinkArrayParser extends AbstractValueParser {
	
	public LinkArrayParser(){
		super( ParsedLinkArray.ID ) ;
	}
	
	@Override
	public ParsedValue parse(String s, IMeta meta, IPropertyProvider propertyProvider,Map<String,Object> metaInfo, String comment)
	{
		String[] strArr = s.split( "\\[\\[" ) ;
		ArrayList<String> strLst = new ArrayList<String>() ;
		for( int i = 0 ; i < strArr.length ; i++ )
		{
			int a = strArr[i].indexOf("]]") ;
			if( a != -1 ){
				String str = strArr[i].substring(0, a) ;
				str = str.replaceAll("(.*)(\\|)(.*)", "$1") ;
				strLst.add( str.trim() ) ;
			}
		}
		if( strLst.size() > 0 )
			return new ParsedLinkArray( strLst, getDefaultComment(comment) ) ;
		else{
			return null ;
		}
	}

}
